package com.cw.websocket;

import com.cw.config.service.impl.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.context.annotation.*;
import org.springframework.web.socket.config.annotation.*;

/**
 * @author sheree Date 2020/7/24
 * @Description
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private SocketHandler socketHandler;

    @Autowired
    private RedisServiceImpl redisService;


    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
	  registry.addHandler(socketHandler, "/socketServer").addInterceptors(
		new WebSocketInterceptor(redisService)).setAllowedOrigins("*");
	  registry.addHandler(socketHandler, "/sockjs/socketServer").setAllowedOrigins("*")
		    .addInterceptors(new WebSocketInterceptor(redisService)).withSockJS();

    }
}
